const express = require("express");
const bodyParser = require("body-parser");
//导入cors包
const cors = require("cors");

const app = express();
const port = 3000;

app.use(bodyParser.json(), cors());

const userInfo = {
  data: {
    data: { token: Math.random().toString(36).substring(0), userName: "赵仲禹" },
    message: "登录成功",
    code: 200,
  },
};
app.post("/user/signIn", (req, res) => {
  console.log(req.body);
  let userName = req.body.userName;
  let passWord = req.body.passWord;
  if (!userName || !passWord) {
    res.send({
      data: {
        code: 500,
        message: "请输入用户名或密码",
      },
    });
  } else {
    if (userName === "admin" && passWord === "111111") {
      res.send(userInfo);
    } else {
      res.send({
        data: {
          code: 500,
          message: "请输入正确的用户名或密码",
        },
      });
    }
  }
});
app.post("/user/signOut", (req, res) => {
  return res.send({
    data: {
      code: 200,
      message: "退出成功",
    },
  });
});
app.get("/dataScreen/info", (req, res) => {
  const data = {option1: [
      { name: "华北", id: 1, value: Math.floor(Math.random() * 100) + 1 },
      { name: "东北", id: 2, value: Math.floor(Math.random() * 100) + 1 },
      { name: "华东", id: 3, value: Math.floor(Math.random() * 100) + 1 },
      { name: "中南", id: 4, value: Math.floor(Math.random() * 100) + 1 },
      { name: "西南", id: 5, value: Math.floor(Math.random() * 100) + 1 },
      { name: "西北", id: 6, value: Math.floor(Math.random() * 100) + 1 },
    ],
    option2:[
      { name: "服务一", id: 1, value: Math.floor(Math.random() * 100) + 1 },
      { name: "服务二", id: 2, value: Math.floor(Math.random() * 100) + 1 },
      { name: "服务三", id: 3, value: Math.floor(Math.random() * 100) + 1 },
      { name: "服务四", id: 4, value: Math.floor(Math.random() * 100) + 1 },
      { name: "服务五", id: 5, value: Math.floor(Math.random() * 100) + 1 },
      { name: "服务六", id: 6, value: Math.floor(Math.random() * 100) + 1 },
    ],
    option3:[
      { name: "华北", id: 1, value: Math.floor(Math.random() * 100) + 1 },
      { name: "东北", id: 2, value: Math.floor(Math.random() * 100) + 1 },
      { name: "华东", id: 3, value: Math.floor(Math.random() * 100) + 1 },
      { name: "中南", id: 4, value: Math.floor(Math.random() * 100) + 1 },
      { name: "西南", id: 5, value: Math.floor(Math.random() * 100) + 1 },
      { name: "西北", id: 6, value: Math.floor(Math.random() * 100) + 1 },
    ]
  };
  return res.send({
    data:{
      data,
      code:200,
      message:'数据获取成功'
    }
  });
});
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});
